
*********************************************************
* The road to reelection is paved with good intentions  *
*														*
* Replication File										*
* Correspondence to:  									*
* talbot.andrews@uconn.edu 								*
*********************************************************

* Packages
	ssc install cibar
	ssc install brewscheme
	ssc install blindschemes
	set scheme plotplain

* Replace the following line with path to folder with replication materials on your machine:
	capture cd "/Users/talbot/Dropbox/Legislator Intentions/Data/Replication Materials" //Talbot's working directory
	
* Running the following code will generate all figures from the main text and appendix
* as .png files, labeled with their figure number.
* Results for all tables and in-text statistics are noted in the code.


*~* Experiment 1 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

use Experiment1Data, clear

* Data Cleaning

	*Good Outcome Recode
		encode PolicyAVote, gen(aVoteIncumbent) 
		replace aVoteIncumbent = aVoteIncumbent-1
		label def inclab 0 "Challenger" 1 "Incumbent"
		label val aVoteIncumbent inclab
		label var aVoteIncumbent "Retain Incumbent if Good Outcome"

	*Bad Outcome Recode
		encode PolicyBVote, gen(bVoteIncumbent) 
		replace bVoteIncumbent = bVoteIncumbent-1
		label val bVoteIncumbent inclab
		label var bVoteIncumbent "Retain Incumbent if Bad Outcome"

	*Intentions Recode
		gen revealedIntention = intention
		replace revealedIntention = . if revealedIntention == -99
		label var revealedIntention "Saw Intended Outcome"

		rename incumbentChoiceBinary goodIntention
		*eliminate the good intention for no noise
		replace goodIntention = . if noise == 0
		replace goodIntention = 0 if goodIntention == 2
		label var goodIntention "Incumbent had Good Intention"

		label def nse 0 "Certain" 20 "20% Noise" 40 "40% Noise"
		label val noise nse

		label def clgr 42 "42 Token Challenger" 46 "46 Token Challenger"
		label val challenger clgr

		gen intention3 = .
		replace intention3 = 0 if intention == 0
		replace intention3 = 1 if intention == 1 & goodIntention == 0
		replace intention3 = 2 if intention == 1 & goodIntention == 1
		label def alb 0 "Private Intentions" 1 "Bad Intentions" 2 "Good Intentions" 
		label val intention3 alb

		///this creates a 4th level of the intentions variables, main Intentions DV
		gen intention4 = intention3+1
		replace intention4 = 0 if noise == 0
		label def ilb 0 "Certain" 1 "Private Intentions" 2 "Bad Intentions" 3 "Good Intentions" 
		label val intention4 ilb
		
		*comparing means across good and bad outcomes
		///Comparing means across outcomes and intention conditions
		rename aVoteIncumbent vote_1
		rename bVoteIncumbent vote_2

		gen id = _n
		reshape long vote_, i(id) j(bad)

		rename bad good
		replace good = 0 if good == 2 & good != .
		label def go 0 "Bad Outcome" 1 "Good Outcome" 
		label val good go
		label var good "1 = Good Outcome, 0 Bad Outcome"

* Main text results

	* Figure 1
		cibar vote_ if intention4 == 0, over(good) ///
			barc(gs6 gs13) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.1).8,grid) xlabel( 1 "Bad Outcome" 2 "Good Outcome") yline(.5) ///
			ytitle("Proportion Voting For Incumbent", height(5)) title("Panel A" "Certain Condition") ///
			xsize(10) ysize(11) ///
			legend(off) name(Fig1_PanelA,replace)) 

		cibar vote_ if intention4 == 1, over(good) ///
			barc(gs6 gs13) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.1).8,grid) xlabel( 1 `" "Bad Outcome"   "(Likely Bad Intentions)" "' 2 `" "Good Outcome"   "(Likely Good Intentions)" "') yline(.5) ///
			ytitle("Proportion Voting For Incumbent", height(5)) title("Panel B" "Private Intentions") ///
			xsize(10) ysize(11) ///
			legend(off) name(Fig1_PanelB,replace)) 
			
		cibar vote_ if intention4 > 1, over(intention4) ///
			barc(gs6 gs13) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.1).8,grid) xlabel( 1 "Bad Intentions" 2 "Good Intentions") yline(.5) ///
			ytitle("Proportion Voting For Incumbent", height(5)) title("Panel C" "Known Intentions") ///
			xsize(10) ysize(11) ///
			legend(off) name(Fig1_PanelC,replace)) 

		cibar vote_ if intention4 > 1, over(good intention4) ///
			barc(gs6 gs13) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.1).8,grid) yline(.5) ///
			ytitle("Proportion Voting For Incumbent", height(5)) title("Panel D" "Known Intentions") ///
			xsize(10) ysize(11) ///
			legend(rows(1) pos(12) ring(0) region(lcolor(black) lpattern(solid))) name(Fig1_PanelD,replace)) 

		graph combine Fig1_PanelA Fig1_PanelB Fig1_PanelC Fig1_PanelD
		graph export fig1.png, height(1500) replace
		
	* Main text analysis
		reg vote_ good##i.intention4, cluster(id)

		* Effect of intentions, pooling across outcomes (known intentions, pg. 16)
		margins intention4, pwcompare(pv)
		
		* Effect of outcomes, polling across intentions (known intentions, pg. 16)
		margins, dydx(good) subpop(if(intention4 > 1))
		
		* Effect of known intentions compared to private intentions (pg. 16)
		margins, dydx(intention4) at(good = (0(1)1))
		
		* Effect of intentions under uncertainty by outcome (pg. 17)
		reg vote_ good##ib1.intention4, cluster(id)
		margins, dydx(intention4) over(good) 
		
		* Effect of certainty, pooling across outcomes (pg. 18)
		reg vote_ good##i.intention4, cluster(id)
		margins intention4, pwcompare(pv)
		
		* Effect of outcome in certain condition (pg. 18)
		margins, dydx(good) subpop(if(intention4 == 0))
		
		* Effect of comprehension in voting correctly in certain condition (pg 18-19)
			* comprehension score calculation
				gen comp1_corr = 0 if(Comp1 != .)
					replace comp1_corr = 1 if(Comp1 == 1)
				gen comp2_corr = 0 if(Comp2 != .)
					replace comp2_corr = 1 if(Comp2 == 1)
				gen comp3_corr = 0 if(Comp3 != .)
					replace comp3_corr = 1 if(Comp3 == 0)
				gen comp4_corr = 0 if(Comp4 != .)
					replace comp4_corr = 1 if(Comp4 == 1)
					
				gen comp_score1 = comp1_corr + comp2_corr + comp3_corr
				gen comp_score2 = comp1_corr + comp2_corr + comp3_corr + comp4_corr
				
				gen comp_score3 = comp_score2
					replace comp_score3 = comp_score1 if comp_score3 == . 
					
				gen comp_score = comp_score3/3 if(comp4_corr == .)
					replace comp_score = comp_score3/4 if(comp4_corr != .)

			* Narrow down to those in certain conditions
			gen comp_score_certain = comp_score
					replace comp_score_certain = . if(intention4 != 0)
			
			* Identify correct voting
			gen correct = 0 if(vote_ == 0 & intention4 == 0 & good == 1)
					replace correct = 1 if(vote_ == 1 & intention4 == 0 & good == 1)
					replace correct = 0 if(vote_ == 1 & intention4 == 0 & good == 0)
					replace correct = 1 if(vote_ == 0 & intention4 == 0 & good == 0)

			* Show those who missed one question vote incorrectly more often
			gen one_wrong = 0 if comp_score_certain == 1
				replace one_wrong = 1 if(comp_score_certain < 1)
				ttest correct, by(one_wrong)
				
* Appendix Results
	
	* Table A1 Column 1: Demographic information
		summarize age
		tab gender
		tab race
		tab party
	
	* Appendix C: Effect of noise in Experiment 1
		gen vote_si = vote_ if(noise == 20)
		gen intention5 = intention4 if(intention4 != 0)

		cibar vote_si, over(intention5 good) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) ///
			title("80% Chance Intention Implemented", size(medlarge)) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(10) ysize(11) ///
			legend(order(1 "Private Intention" 2 "Bad Intention" 3 "Good Intention") ///
			rows(3) pos(2) ring(0) region(lcolor(black) lpattern(solid))) ///
			saving(low_uncertainty, replace)) 

		gen vote_si2 = vote_ if(noise == 40)

		cibar vote_si2, over(intention5 good) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) ///
			title("60% Chance Intention Implemented", size(medlarge)) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(10) ysize(11) ///
			legend(order(1 "Private Intention" 2 "Bad Intention" 3 "Good Intention") ///
			rows(3) pos(2) ring(0) region(lcolor(black) lpattern(solid))) ///
			saving(high_uncertainty, replace))  
			
		gr combine low_uncertainty.gph high_uncertainty.gph
		graph export figC1.png, height(1500) replace
	
	* Appendix D: Comprehension and its effects on behavior
		* Figure D1: Distribution of comprehension scores in Experiment 1
		hist comp_score if(comp4_corr != .), percent title("Private and Known Intentions") ///
			xtitle("Questions Correct", size(medlarge)) xlabel(0 "0" 0.25 "1" 0.5 "2" 0.75 "3" 1 "4", labsize(medlarge)) ///
			width(0.2) saving(score_noise.gph, replace)
			
		hist comp_score if(comp4_corr == .), percent title("Certain") ///
			xtitle("Questions Correct", size(medlarge)) xlabel(0 "0" 0.33 "1" 0.66 "2" 1 "3", labsize(medlarge)) ///
			width(0.3) saving(score_certain.gph, replace)
			
		gr combine score_certain.gph score_noise.gph, title("Experiment 1", size(medlarge)) ycommon
		graph export figD1.png, height(1500) replace
		
		* Figure D4: Voting behavior in Exp 1 by comprehension score
		cibar vote_, over(intention4 good) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(10) ysize(11) title("Full Sample", ring(0)) ///
			legend(rows(1) pos(2) ring(0) region(lcolor(black) lpattern(solid))) /// 
			saving(Exp1_Full, replace))

		gen vote_allright = vote_ if(comp_score == 1)

		cibar vote_allright, over(intention4 good) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid)  ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(10) ysize(11) title("All Comprehension Questions Correct", ring(0)) ///
			legend(rows(1) pos(2) ring(0) region(lcolor(black) lpattern(solid))) ///
			saving(Exp1_allright, replace)) 

		grc1leg2 Exp1_Full.gph Exp1_allright.gph, legendfrom(Exp1_Full.gph) pos(6)
		graph export figD4.png, height(1500) replace
		
	* Appendix E: Risk preferences and their effect on behavior
		* Figure E1: Distribution of risk preferences in Exp 1
		gen gamblec = 1 if gamblechoice == "Gamble 1"
		replace gamblec = 2 if  gamblechoice == "Gamble 2"
		replace gamblec = 3 if  gamblechoice == "Gamble 3"
		replace gamblec = 4 if  gamblechoice == "Gamble 4"
		replace gamblec = 5 if  gamblechoice == "Gamble 5"
		replace gamblec = 6 if  gamblechoice == "Gamble 6"
		
		hist gamblec, percent xlabel(, labsize(medlarge)) xtitle("Gamble Choice", size(med)) ///
			title("Experiment 1") barwidth(0.5) saving(figE1_p1, replace)
		
		* Ttest for incumbent vote by risk preferences			
		gen high_risk = 0 if(gamblec < 3)
			replace high_risk = 1 if(gamblec > 2)
			
		ttest vote_ if intention4 > 0, by(high_risk) 
		
		* Table E1, Column 1
		reg vote_ i.good##i.intention4##c.gamblec, cluster(id)
		
		* Figure E2, Panel 1
		reg vote_ i.good##i.intention4##c.gamblec, cluster(id)
		margins, at(gamblec = (1(1)6)) over(good)
		marginsplot, recastci(rarea) ///
			plot1opts(msymbol(square) color("235 189 200") lpattern(solid)) ci1opts(color("235 189 200%30")) ///
			plot2opts(msymbol(diamond) color("172 142 170") lpattern(solid)) ci2opts(color("172 142 170%20")) ///
			title("Experiment 1", ring(0)) xlabel(1 `" "Risk"  "Averse" "' 2 "2" 3 "3" 4 "4" 5 "5" 6 `" "Risk"  "Seeking" "', nogrid) ///
			xtitle("Risk Preference") ytitle("Pr(Vote for Incumbent)") ylabel(0(.2)1, nogrid) saving(figE2_p1, replace)
		
		* Figure E3, Panel 1
		reg vote_ i.good##i.intention4##c.gamblec, cluster(id)
		margins, at(gamblec = (1(1)6)) over(intention4)
		marginsplot, recastci(rarea) ///
			plot1opts(msymbol(circle) color("224 206 190") lpattern(solid)) ci1opts(color("248 227 208%50")) ///
			plot2opts(msymbol(square) color("235 189 200") lpattern(solid)) ci2opts(color("235 189 200%30")) ///
			plot3opts(msymbol(diamond) color("172 142 170") lpattern(solid)) ci3opts(color("172 142 170%20")) ///
			plot4opts(msymbol(triangle) lcolor(black) lpattern(solid)) ci4opts(color(black%10)) ///
			title("Experiment 1", ring(0)) xlabel(1 `" "Risk"  "Averse" "' 2 "2" 3 "3" 4 "4" 5 "5" 6 `" "Risk"  "Seeking" "', nogrid) ///
			xtitle("Risk Preference") ytitle("Pr(Vote for Incumbent)") ylabel(0(.2)1, nogrid) saving(figE3_p1, replace)
			
	* Appendix F: Regression results and non-parametric tests
		* Table F1, Column 1: Parametric results for Exp 1
		reg vote_ good##i.intention4, cluster(id)
		
		* Table F2: Non-parametric results for Exp 1
		* good v bad
		ranksum vote_ if(intention4 != 0 & intention4 != 1 & good == 1), by(intention4) // good outcome
		ranksum vote_ if(intention4 != 0 & intention4 != 1 & good == 0), by(intention4) // bad outcome
		
		* good v private
		ranksum vote_ if(intention4 != 0 & intention4 != 2 & good == 1), by(intention4) // good outcome
		ranksum vote_ if(intention4 != 0 & intention4 != 2 & good == 0), by(intention4) // bad outcome
		
		* good v certain
		ranksum vote_ if(intention4 != 1 & intention4 != 2 & good == 1), by(intention4) // good outcome
		ranksum vote_ if(intention4 != 1 & intention4 != 2 & good == 0), by(intention4) // bad outcome
		
		* bad v private
		ranksum vote_ if(intention4 != 0 & intention4 != 3 & good == 1), by(intention4) // good outcome
		ranksum vote_ if(intention4 != 0 & intention4 != 3 & good == 0), by(intention4) // bad outcome
		
		* bad v certain
		ranksum vote_ if(intention4 != 1 & intention4 != 3 & good == 1), by(intention4) // good outcome
		ranksum vote_ if(intention4 != 1 & intention4 != 3 & good == 0), by(intention4) // bad outcome
		
		* certain v private
		ranksum vote_ if(intention4 != 2 & intention4 != 3 & good == 1), by(intention4) // good outcome
		ranksum vote_ if(intention4 != 2 & intention4 != 3 & good == 0), by(intention4) // bad outcome

		* Figure F1: Proportion voting to reelect incumbent
		cibar vote_, over(intention4 good) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(10) ysize(11)  ///
			legend(rows(2) pos(12) ring(0) region(lcolor(black) lpattern(solid)))) 
		graph export figF1.png, height(1500) replace

		
*~* Experiment 2 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

use Experiment2Data, clear

* Cleaning
		gen aVoteIncumbent = (PolicyAVote == 1) if PolicyAVote != .
		label def inclab 0 "Challenger" 1 "Incumbent"
		label val aVoteIncumbent inclab
		label var aVoteIncumbent "Retain Incumbent if Good Outcome"

		gen bVoteIncumbent = (PolicyBVote == 1) if PolicyBVote != .
		label val bVoteIncumbent inclab
		label var bVoteIncumbent "Retain Incumbent if Bad Outcome"

		gen revealedIntention = intention
		replace revealedIntention = . if revealedIntention == -99
		label var revealedIntention "Saw Intended Outcome"

		gen aVoteGoodIntent = (VoteIntentionAA == 1) if VoteIntentionAA != .
		label val aVoteGoodIntent inclab
		label var aVoteGoodIntent "Retain Incumbent if Good Outcome + Good Intention" 

		gen aVoteBadIntent = (VoteIntentionBA == 1) if VoteIntentionBA != .
		label val aVoteBadIntent inclab
		label var aVoteBadIntent "Retain Incumbent if Good Outcome + Bad Intention"

		gen bVoteGoodIntent = (VoteIntentionAB == 1) if VoteIntentionAB != .
		label val bVoteGoodIntent inclab
		label var bVoteGoodIntent "Retain Incumbent if Bad Outcome + Good Intention"

		gen bVoteBadIntent = (VoteIntentionBB == 1) if VoteIntentionBB != .
		label val bVoteBadIntent inclab
		label var bVoteBadIntent "Retain Incumbent if Bad Outcome + Bad Intention"

		gen id = _n

	////The code below will create a stack of the intention conditions that did with the strategy method (i.e 1 participant has 2 observations for each policy [1 for good and 1 for bad])
		gen clone = 0
		tempfile temp1
		save "`temp1'"
		drop clone
		drop if intention != 1
		gen clone = 1
		append using "`temp1'"

	*This classification only works for the DVs created moving forward [the cloned person from the intentions condition is in both good and bad intentions)
		gen intention4 = .
		replace intention4 = 0 if intention == -99
		replace intention4 = 1 if intention == 0
		replace intention4 = 2 if intention == 1 & clone == 1
		replace intention4 = 3 if intention == 1 & clone == 0
		label def alb 0 "Certain" 1 "Private Intentions" 2 "Bad Intentions" 3 "Good Intentions" 
		label val intention4 alb

		gen AIncumbent = aVoteIncumbent
		replace AIncumbent = aVoteBadIntent if intention == 1 & clone == 1
		replace AIncumbent = aVoteGoodIntent if intention == 1 & clone == 0 
		label val AIncumbent inclab
		label var AIncumbent "Retain Incumbent if Good Outcome"

		gen BIncumbent = bVoteIncumbent
		replace BIncumbent = bVoteBadIntent if intention == 1 & clone == 1
		replace BIncumbent = bVoteGoodIntent if intention == 1 & clone == 0 
		label val BIncumbent inclab
		label var BIncumbent "Retain Incumbent if Bad Outcome"
		
		rename AIncumbent vote_1
		rename BIncumbent vote_2

	*This will uniquely identify rows, pre-reshape while id identifies observations
		gen id2 = _n

		reshape long vote_, i(id2) j(bad)

		replace bad = bad-1
		label def bo 0 "Good Outcome" 1 "Bad Outcome" 
		label val bad bo
		label var bad "1 = Bad Outcome, 0 Good Outcome"
		
		gen good = 0 if bad == 1
		replace good = 1 if bad == 0
		label def go 0 "Bad Outcome" 1 "Good Outcome" 
		label val good go
		label var good "1 = Good Outcome, 0 Bad Outcome"

* Main Text Results

	* Figure 2
	cibar vote_ if intention4 == 0, over(good) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.2)1,grid) xlabel( 1 "Bad Outcome" 2 "Good Outcome") yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel A" "Certain Condition") ///
		xsize(10) ysize(11) ///
		legend(off) saving(Fig1_PanelA, replace)) 
	
	cibar vote_ if intention4 == 1, over(good) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.2)1,grid) xlabel( 1 `" "Bad Outcome"   "(Likely Bad Intentions)" "' 2 `" "Good Outcome"   "(Likely Good Intentions)" "') yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel B" "Private Intentions") ///
		xsize(10) ysize(11) ///
		legend(off) saving(Fig1_PanelB, replace)) 
		
	cibar vote_ if intention4 > 1, over(intention4) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.2)1,grid) xlabel( 1 "Bad Intentions" 2 "Good Intentions") yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel C" "Known Intentions") ///
		xsize(10) ysize(11) ///
		legend(off) saving(Fig1_PanelC, replace)) 

	cibar vote_ if intention4 > 1, over(good intention4) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.2)1,grid) yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel D" "Known Intentions") ///
		xsize(10) ysize(11) ///
		legend(rows(2) pos(10) ring(0)  region(lcolor(black) lpattern(solid))) saving(Fig1_PanelD, replace)) 
		
	gr combine Fig1_PanelA.gph Fig1_PanelB.gph Fig1_PanelC.gph Fig1_PanelD.gph
	graph export fig2.png, heigh(1500) replace
	
	* Effect of outcomes, polling across intentions (pg. 21)
	reg vote_ good##i.intention4 if intention4 > 1, cluster(id)
	margins, dydx(good) 
		
	* Effect of intentions, pooling across outcomes (pg. 21)
	margins, dydx(intention4)
	
	* Effect of intentions (known vs private) across outcomes (pg. 22)
	reg vote_ good##ib1.intention4, cluster(id)
		margins, dydx(intention4) over(good)
	
* Appendix Results

	* Appendix A: Sample characteristics
		* Table A1, Column 2
		mean age
		tab gender
		tab race
		tab party
	
	* Appendix D: Comprehension and effects on behavior
		
		* Figure D2: Distribution of comprehension question scores in Experiment 2
	 		gen comp1_corr = 0 if(Comp1 != .)
				replace comp1_corr = 1 if(Comp1 == 1)
			gen comp2_corr = 0 if(Comp2 != .)
				replace comp2_corr = 1 if(Comp2 == 1)
			gen comp3_corr = 0 if(Comp3 != .)
				replace comp3_corr = 1 if(Comp3 == 2)
			gen comp4_corr = 0 if(Comp4 != .)
				replace comp4_corr = 1 if(Comp4 == 1)
				
			gen comp_score1 = comp1_corr + comp2_corr + comp3_corr
			gen comp_score2 = comp1_corr + comp2_corr + comp3_corr + comp4_corr
			
			gen comp_score3 = comp_score2
				replace comp_score3 = comp_score1 if comp_score3 == . 
				
			gen comp_score = comp_score3/3 if(comp4_corr == .)
				replace comp_score = comp_score3/4 if(comp4_corr != .)
				
		hist comp_score if(comp4_corr != .), percent title("Private and Known Intentions") ///
			xtitle("Questions Correct", size(medlarge)) xlabel(0 "0" 0.25 "1" 0.5 "2" 0.75 "3" 1 "4", labsize(medlarge)) ///
			width(0.2) saving(score_noise.gph, replace)
			
		hist comp_score if(comp4_corr == .), percent title("Certain") ///
			xtitle("Questions Correct", size(medlarge)) xlabel(0 "0" 0.33 "1" 0.66 "2" 1 "3", labsize(medlarge)) ///
			width(0.3) saving(score_certain.gph, replace)

		gr combine score_certain.gph score_noise.gph, ycommon
		graph export figD2.png, height(1500) replace
	
		* Figure D5: Voting behavior across conditions by comprehension 
		cibar vote_, over(intention4 good) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(10) ysize(11) title("Full Sample", ring(0)) ///
			legend(rows(1) pos(2) ring(0) region(lcolor(black) lpattern(solid))) /// 
			saving(Exp2_Full, replace))

		gen vote_allright = vote_ if(comp_score == 1)

		cibar vote_allright, over(intention4 good) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid)  ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(10) ysize(11) title("All Comprehension Questions Correct", ring(0)) ///
			legend(rows(1) pos(2) ring(0) region(lcolor(black) lpattern(solid))) ///
			saving(Exp2_allright, replace)) 

		grc1leg2 Exp2_Full.gph Exp2_allright.gph, legendfrom(Exp2_Full.gph) pos(6)
		graph export figD5.png, height(1500) replace
		
	* Appendix E: Risk preferences and their effect on behavior
		
		* Figure E1, Panel 2: Distribution of risk preferences
		gen gamblec = gamblechoice
			
		hist gamblec, percent xlabel(, labsize(medlarge)) xtitle("Gamble Choice", size(med)) ///
			title("Experiment 2") barwidth(0.5) saving(figE1_p2, replace)
		
		* Ttest for incumbent vote by risk preference
		gen high_risk = 0 if(gamblec < 3)
			replace high_risk = 1 if(gamblec > 2)
		
		ttest vote_ if intention4 > 0, by(high_risk) 
		
		* Figure E2, Panel 2
		reg vote_ i.good##i.intention4##c.gamblec, cluster(id)
		margins, at(gamblec = (1(1)6)) over(good)
			marginsplot, recastci(rarea) ///
				plot1opts(msymbol(square) color("235 189 200") lpattern(solid)) ci1opts(color("235 189 200%30")) ///
				plot2opts(msymbol(diamond) color("172 142 170") lpattern(solid)) ci2opts(color("172 142 170%20")) ///
				title("Experiment 2", ring(0)) xlabel(1 `" "Risk"  "Averse" "' 2 "2" 3 "3" 4 "4" 5 "5" 6 `" "Risk"  "Seeking" "', nogrid) ///
				saving(figE2_p2, replace)
		
		
		* Figure E3, Panel 2
		reg vote_ i.good##i.intention4##c.gamblec, cluster(id)
		margins, at(gamblec = (1(1)6)) over(intention4)
			marginsplot, recastci(rarea) ///
				plot1opts(msymbol(circle) color("224 206 190") lpattern(solid)) ci1opts(color("248 227 208%50")) ///
				plot2opts(msymbol(square) color("235 189 200") lpattern(solid)) ci2opts(color("235 189 200%30")) ///
				plot3opts(msymbol(diamond) color("172 142 170") lpattern(solid)) ci3opts(color("172 142 170%20")) ///
				plot4opts(msymbol(triangle) lcolor(black) lpattern(solid)) ci4opts(color(black%10)) ///
				title("Experiment 2", ring(0)) xlabel(1 `" "Risk"  "Averse" "' 2 "2" 3 "3" 4 "4" 5 "5" 6 `" "Risk"  "Seeking" "', nogrid) ///
				xtitle("Risk Preference") ytitle("Pr(Vote for Incumbent)") ylabel(0(.2)1, nogrid) saving(figE3_p2, replace)
			
		* Table E1, Column 2
		reg vote_ i.good##i.intention4##c.gamblec, cluster(id)
		
	* Appendix F: Regression results and non-parametric tests
		
		* Table F1, Column 2
			reg vote_ good##i.intention4, cluster(id)
		
		* Table F3: Non-parametric results
			* good v bad
			ranksum vote_ if(intention4 != 0 & intention4 != 1 & good == 1), by(intention4) // good outcome
			ranksum vote_ if(intention4 != 0 & intention4 != 1 & good == 0), by(intention4) // bad outcome
			
			* good v private
			ranksum vote_ if(intention4 != 0 & intention4 != 2 & good == 1), by(intention4) // good outcome
			ranksum vote_ if(intention4 != 0 & intention4 != 2 & good == 0), by(intention4) // bad outcome
			
			* good v certain
			ranksum vote_ if(intention4 != 1 & intention4 != 2 & good == 1), by(intention4) // good outcome
			ranksum vote_ if(intention4 != 1 & intention4 != 2 & good == 0), by(intention4) // bad outcome
			
			* bad v private
			ranksum vote_ if(intention4 != 0 & intention4 != 3 & good == 1), by(intention4) // good outcome
			ranksum vote_ if(intention4 != 0 & intention4 != 3 & good == 0), by(intention4) // bad outcome
			
			* bad v certain
			ranksum vote_ if(intention4 != 1 & intention4 != 3 & good == 1), by(intention4) // good outcome
			ranksum vote_ if(intention4 != 1 & intention4 != 3 & good == 0), by(intention4) // bad outcome
			
			* certain v private
			ranksum vote_ if(intention4 != 2 & intention4 != 3 & good == 1), by(intention4) // good outcome
			ranksum vote_ if(intention4 != 2 & intention4 != 3 & good == 0), by(intention4) // bad outcome
		
		* Figure F2: Proportion voting to reelect the incumbent
		cibar vote_, over(intention4 good) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(10) ysize(11) ///
			legend(rows(2) pos(12) region(lcolor(black) lpattern(solid))))
		graph export figF2.png, height(1500) replace
		

*~* Experiment 3 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

use Experiment3Data, clear

* Cleaning Data
	gen aVoteIncumbent = (PolicyAVote == 1) if PolicyAVote != .
	label def inclab 0 "Challenger" 1 "Incumbent"
	label val aVoteIncumbent inclab
	label var aVoteIncumbent "Retain Incumbent if Good Outcome"

	gen bVoteIncumbent = (PolicyBVote == 1) if PolicyBVote != .
	label val bVoteIncumbent inclab
	label var bVoteIncumbent "Retain Incumbent if Bad Outcome"

	gen revealedIntention = intention
	replace revealedIntention = . if revealedIntention == -99
	label var revealedIntention "Saw Intended Outcome"

	gen aVoteGoodIntent = (AAIntentionVote == 1) if AAIntentionVote != .
	label val aVoteGoodIntent inclab
	label var aVoteGoodIntent "Retain Incumbent if Good Outcome + Good Intention" 

	gen aVoteBadIntent = (BAIntentionVote == 1) if BAIntentionVote != .
	label val aVoteBadIntent inclab
	label var aVoteBadIntent "Retain Incumbent if Good Outcome + Bad Intention"

	gen bVoteGoodIntent = (ABIntentionVote == 1) if ABIntentionVote != .
	label val bVoteGoodIntent inclab
	label var bVoteGoodIntent "Retain Incumbent if Bad Outcome + Good Intention"

	gen bVoteBadIntent = (BBIntentionVote == 1) if BBIntentionVote != .
	label val bVoteBadIntent inclab
	label var bVoteBadIntent "Retain Incumbent if Bad Outcome + Bad Intention"

	////The code below will create a stack of the intention conditions that we had do the strategy method, in order to generate the following figures

	gen clone = 0
	tempfile temp1
	save "`temp1'"
	drop clone
	drop if intention != 1
	gen clone = 1
	append using "`temp1'"

	*This classification only works for the DVs created after 
	gen intention4 = .
	replace intention4 = 0 if intention == -99
	replace intention4 = 1 if intention == 0
	replace intention4 = 2 if intention == 1 & clone == 1
	replace intention4 = 3 if intention == 1 & clone == 0
	label def alb 0 "Certain" 1 "Private Intentions" 2 "Bad Intentions" 3 "Good Intentions" 
	label val intention4 alb

	gen AIncumbent = aVoteIncumbent
	replace AIncumbent = aVoteBadIntent if intention == 1 & clone == 1
	replace AIncumbent = aVoteGoodIntent if intention == 1 & clone == 0 
	label val AIncumbent inclab
	label var AIncumbent "Retain Incumbent if Good Outcome"

	gen BIncumbent = bVoteIncumbent
	replace BIncumbent = bVoteBadIntent if intention == 1 & clone == 1
	replace BIncumbent = bVoteGoodIntent if intention == 1 & clone == 0 
	label val BIncumbent inclab
	label var BIncumbent "Retain Incumbent if Bad Outcome"

* Note: Results presented out of order from main text and appendix due to required reshapes for generating main text figures

* Appendix Results (part 1)

	* Appendix A: Sample Characteristics
	* Table A1, Column 3
	mean age
	tab gender
	tab race
	tab party
	
	* Appendix G: Additional group conditions
	
		* Figure G1
		cibar AIncumbent, over(intention4 challengerOutgroup incumbentOutgroup) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid)  ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(8) ysize(5) title("Good Policy Outcome", size(medlarge)) ///
			legend(off) ///
			saving(good_outcome, replace))

		cibar BIncumbent, over(intention4 challengerOutgroup incumbentOutgroup) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid)  ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(8) ysize(5) title("Bad Policy Outcome", size(medlarge)) ///
			legend(rows(2) pos(2) ring(0) region(lcolor(black) lpattern(solid))) ///
			saving(bad_outcome, replace))
			
		gr combine good_outcome.gph bad_outcome.gph, col(1)
		graph export figG1.png, height(1500) replace		
	
	* Appendix D: Comprehension
		///Dropping conditions not analyzed in the rest of the data
		*keep what we need for conditions
		drop if incumbentOut == 1 & challengerOut == 1
		drop if incumbentOut == 0 & challengerOut == 0

		gen outin = 0 if incumbentOut == 0 & challengerOut == 1
		replace outin = 1 if incumbentOut == 1 & challengerOut == 0
		label def oi 0 "Ingroup Incumbent" 1 "Outgroup Incumbent"
		label val outin oi
	
		* Figure D3: Distribution of comprehension scores
			gen comp1_corr = 0 if(Comp1 != .)
				replace comp1_corr = 1 if(Comp1 == 1)
			gen comp2_corr = 0 if(Comp2 != .)
				replace comp2_corr = 1 if(Comp2 == 1)
			gen comp3_corr = 0 if(Comp3 != .)
				replace comp3_corr = 1 if(Comp3 == 2)
			gen comp4_corr = 0 if(Comp4 != .)
				replace comp4_corr = 1 if(Comp4 == 1)
				
			gen comp_score = (comp1_corr + comp2_corr + comp3_corr + comp4_corr)/4

		hist comp_score, percent  ///
			xtitle("Questions Correct", size(medlarge)) xlabel(0 "0" 0.25 "1" 0.5 "2" 0.75 "3" 1 "4", labsize(medlarge)) ///
			width(0.2) 
		graph export figD3.png, height(1500) replace
		
		* Figure D6: Voting behavior by comprehension (Bad policy Outcome)
		gen AIncumbent_main = AIncumbent if(challengerOutgroup == 1 & incumbentOutgroup == 0)
		replace AIncumbent_main = AIncumbent if(challengerOutgroup == 0 & incumbentOutgroup == 1)
		
		gen BIncumbent_main = BIncumbent if(challengerOutgroup == 1 & incumbentOutgroup == 0)
		replace BIncumbent_main = BIncumbent if(challengerOutgroup == 0 & incumbentOutgroup == 1)
		
		gen AIncumbent_main_allright = AIncumbent_main if(comp_score == 1)
		gen BIncumbent_main_allright = BIncumbent_main if(comp_score == 1)
		
		cibar BIncumbent_main, over1(intention4) over2(incumbentOutgroup) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.25)1,grid labsize(med)) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(8) ysize(5) title("Bad Policy Outcome" "Full Sample", ring(0) size(medlarge)) xlabel( , labsize(med)) ///
			legend(rows(1) pos(2) ring(0) region(lcolor(black) lpattern(solid)) size(med)) ///
			saving(bad_groups_full, replace))
			
		cibar BIncumbent_main_allright, over1(intention4) over2(incumbentOutgroup) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.25)1,grid labsize(med)) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(8) ysize(5) ///
			title("Bad Policy Outcome" "All Comprehension Questions Correct", ring(0) size(medlarge)) xlabel( , labsize(med)) ///
			legend(rows(1) pos(2) ring(0) region(lcolor(black) lpattern(solid)) size(med)) ///
			saving(bad_groups_alright, replace))
			
		grc1leg2 bad_groups_Full.gph bad_groups_alright.gph, legendfrom(bad_groups_Full.gph) pos(6)
			graph export figD6.png, height(1500) replace
		
		* Figure D7: Voting behavior by comprehension (Good policy Outcome)
		cibar AIncumbent_main, over1(intention4) over2(incumbentOutgroup) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.25)1,grid labsize(med)) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(8) ysize(5) title("Good Policy Outcome" "Full Sample", ring(0) size(medlarge)) xlabel( , labsize(med)) ///
			legend(rows(1) pos(2) ring(0) region(lcolor(black) lpattern(solid)) size(med)) ///
			saving(good_groups_full, replace))
			
		cibar AIncumbent_main_allright, over1(intention4) over2(incumbentOutgroup) ///
			barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
			ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.25)1,grid labsize(med)) ///
			ytitle("Proportion Voting For Incumbent", height(5)) ///
			xsize(8) ysize(5) ///
			title("Good Policy Outcome" "All Comprehension Questions Correct", ring(0) size(medlarge)) xlabel( , labsize(med)) ///
			legend(rows(1) pos(2) ring(0) region(lcolor(black) lpattern(solid)) size(med)) ///
			saving(good_groups_alright, replace))
			
		grc1leg2 good_groups_Full.gph good_groups_alright.gph, legendfrom(good_groups_Full.gph) pos(6)
			graph export figD7.png, height(1500) replace
			
	* Appendix E: Risk preferences and their effect on behavior
	
		* Figure E1, Panel 3
		gen gamblec = gamblechoice
			
		hist gamblec, percent xlabel(, labsize(medlarge)) xtitle("Gamble Choice", size(med)) ///
			title("Experiment 3") barwidth(0.5) saving(figE1_p3, replace)
		
		* Ttest results
		gen high_risk = 0 if(gamblec < 3)
		replace high_risk = 1 if(gamblec > 2)
		
		ttest AIncumbent_main if intention4 > 0, by(high_risk) 
		ttest BIncumbent_main if intention4 > 0, by(high_risk) 
		
	* Appendix F: Regression results and non-parametric tests
	
	* Figure F3:
	cibar AIncumbent, over(intention4 outin) ///
		barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid)  ///
		ytitle("Proportion Voting For Incumbent", height(5)) ///
		xsize(8) ysize(5) title("Good Policy Outcome", size(medlarge)) ///
		legend(rows(2) pos(12) ring(0) region(lcolor(black) lpattern(solid))) ///
		saving(good_outcome, replace))

	cibar BIncumbent, over(intention4 outin) ///
		barc(gs16 gs13 gs9 gs6) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid)  ///
		ytitle("Proportion Voting For Incumbent", height(5)) ///
		xsize(8) ysize(5) title("Bad Policy Outcome", size(medlarge)) ///
		legend(off) ///
		saving(bad_outcome, replace))
		
	gr combine good_outcome.gph bad_outcome.gph, col(1)
	graph export figF3.png, height(1500) replace


* Main text

	*Make the outcomes collapsible 
	rename AIncumbent vote_1
	rename BIncumbent vote_2

	gen id = _n
	reshape long vote_, i(id) j(bad)

	rename bad good
	replace good = 0 if good == 2 & good != .
	label def go 0 "Bad Outcome" 1 "Good Outcome" 
	label val good go
	label var good "1 = Good Outcome, 0 Bad Outcome"
	
	* Figure 3
	cibar vote_ if intention4 == 0, over(outin good) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) xlabel( 1.5 "Bad Outcome" 4.25 "Good Outcome") yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel A" "Certain Condition") ///
		xsize(10) ysize(11) ///
		legend(rows(1) pos(12) ring(0) region(lcolor(black) lpattern(solid))) name(Fig3_PanelA,replace) ///
		saving(Fig3_PanelA,replace))

	cibar vote_ if intention4 == 1, over(outin good) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) xlabel( 1.5 `" "Bad Outcome"   "(Likely Bad Intentions)" "' 4.25 `" "Good Outcome"   "(Likely Good Intentions)" "') yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5))  title("Panel B" "Private Intentions") ///
		xsize(10) ysize(11) ///
		legend(rows(1) pos(12) ring(0) region(lcolor(black) lpattern(solid))) name(Fig3_PanelB,replace) ///
		saving(Fig3_PanelB,replace))

	cibar vote_ if intention4 > 1, over(outin intention4) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) xlabel( 1.5 "Bad Intentions" 4.25 "Good Intentions") yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel C" "Known Intentions") ///
		xsize(10) ysize(11) ///
		legend(rows(1) pos(12) ring(0) region(lcolor(black) lpattern(solid))) name(Fig3_PanelC,replace) ///
		saving(Fig3_PanelC,replace))

	cibar vote_ if intention4 > 1, over(outin good intention4 ) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid) xlabel(,labsize(vsmall)) yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel D" "Known Intentions") ///
		xsize(10) ysize(11) ///
		legend(rows(1) pos(12) ring(0) region(lcolor(black) lpattern(solid))) name(Fig3_PanelD,replace) ///
		saving(Fig3_PanelD,replace))

	grc1leg2 Fig3_PanelA.gph Fig3_PanelB.gph Fig3_PanelC.gph Fig3_PanelD.gph, legendfrom(Fig3_PanelA.gph)
	graph export fig3.png, height(1500) replace
	
	* In-text Analysis
	
	* Reward in and out-group incumbents who have good outcomes (pg 25)
	reg vote_ good##i.intention4##outin if intention4 > 1, cluster(id)
	margins, dydx(good) over(outin) 
	
	* Only ingroup incumbents significantly rewarded for good intentions (pg 25)
	margins, dydx(intention4) over(outin) 
	
	* Preference for in-group incumbents (pg 26)
	margins, dydx(outin) over(intention4) at(good = (0(1)1))
	
* Appendix Results (Part 2)		

	* Appendix E: Risk preferences and their effect on behavior
	
		* Figure E2, Panel 3
		reg vote_ i.good##i.intention4##c.gamblec if outin == 0, cluster(id)
		margins, at(gamblec = (1(1)6)) over(good)
			marginsplot, recastci(rarea) ///
				plot1opts(msymbol(square) color("235 189 200") lpattern(solid)) ci1opts(color("235 189 200%30")) ///
				plot2opts(msymbol(diamond) color("172 142 170") lpattern(solid)) ci2opts(color("172 142 170%20")) ///
				title("Experiment 3" "Ingroup Incumbent", ring(0)) xlabel(1 `" "Risk"  "Averse" "' 2 "2" 3 "3" 4 "4" 5 "5" 6 `" "Risk"  "Seeking" "', nogrid) ///
				xtitle("Risk Preference") ytitle("Pr(Vote for Incumbent)") ylabel(0(.2)1, nogrid) saving(figE2_p3, replace)
			
		* Figure E2, Panel 4
		reg vote_ i.good##i.intention4##c.gamblec, cluster(id)
		margins, at(gamblec = (1(1)6)) over(good)
			marginsplot, recastci(rarea) ///
				plot1opts(msymbol(square) color("235 189 200") lpattern(solid)) ci1opts(color("235 189 200%30")) ///
				plot2opts(msymbol(diamond) color("172 142 170") lpattern(solid)) ci2opts(color("172 142 170%20")) ///
				title("Experiment 3" "Outgroup Incumbent", ring(0)) xlabel(1 `" "Risk"  "Averse" "' 2 "2" 3 "3" 4 "4" 5 "5" 6 `" "Risk"  "Seeking" "', nogrid) ///
				xtitle("Risk Preference") ytitle("Pr(Vote for Incumbent)") ylabel(0(.2)1, nogrid) saving(figE2_p4, replace)
			
		* Figure E3, Panel 3
		reg vote_ i.good##i.intention4##c.gamblec if outin == 0, cluster(id)
		margins, at(gamblec = (1(1)6)) over(intention4)
			marginsplot, recastci(rarea) ///
				plot1opts(msymbol(circle) color("224 206 190") lpattern(solid)) ci1opts(color("248 227 208%50")) ///
				plot2opts(msymbol(square) color("235 189 200") lpattern(solid)) ci2opts(color("235 189 200%30")) ///
				plot3opts(msymbol(diamond) color("172 142 170") lpattern(solid)) ci3opts(color("172 142 170%20")) ///
				plot4opts(msymbol(triangle) lcolor(black) lpattern(solid)) ci4opts(color(black%10)) ///
				title("Experiment 3" "Ingroup Incumbent", ring(0)) xlabel(1 `" "Risk"  "Averse" "' 2 "2" 3 "3" 4 "4" 5 "5" 6 `" "Risk"  "Seeking" "', nogrid) ///
				xtitle("Risk Preference") ytitle("Pr(Vote for Incumbent)") ylabel(0(.2)1, nogrid) saving(figE3_p3, replace)
		
		* Figure E3, Panel 4
		reg vote_ i.good##i.intention4##c.gamblec if outin == 1, cluster(id)
		margins, at(gamblec = (1(1)6)) over(intention4)
			marginsplot, recastci(rarea) ///
				plot1opts(msymbol(circle) color("224 206 190") lpattern(solid)) ci1opts(color("248 227 208%50")) ///
				plot2opts(msymbol(square) color("235 189 200") lpattern(solid)) ci2opts(color("235 189 200%30")) ///
				plot3opts(msymbol(diamond) color("172 142 170") lpattern(solid)) ci3opts(color("172 142 170%20")) ///
				plot4opts(msymbol(triangle) lcolor(black) lpattern(solid)) ci4opts(color(black%10)) ///
				title("Experiment 3" "Outgroup Incumbent", ring(1)) xlabel(1 `" "Risk"  "Averse" "' 2 "2" 3 "3" 4 "4" 5 "5" 6 `" "Risk"  "Seeking" "', nogrid) ///
				xtitle("Risk Preference") ytitle("Pr(Vote for Incumbent)") ylabel(0(.2)1, nogrid) ///
				legend(col(2) pos(12)) saving(figE3_p4, replace)
			
		* Table E1, Column 3
		reg vote_ i.good##i.intention4##c.gamblec if outin == 0, cluster(id)
		
		* Table E1, Column 4
		reg vote_ i.good##i.intention4##c.gamblec if outin == 1, cluster(id)
		
	* Appendix F: Regression results and non-parametric tests
	
		* Table F1, Column 3
		reg vote_ good##i.intention4##outin, cluster(id)
		
		* Table F4: Non-parametric results
			* Ingroup 
				* good v bad
				ranksum vote_ if(intention4 != 0 & intention4 != 1 & good == 1 & outin == 0), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 0 & intention4 != 1 & good == 0 & outin == 0), by(intention4) // bad outcome
				
				* good v private
				ranksum vote_ if(intention4 != 0 & intention4 != 2 & good == 1 & outin == 0), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 0 & intention4 != 2 & good == 0 & outin == 0), by(intention4) // bad outcome
				
				* good v certain
				ranksum vote_ if(intention4 != 1 & intention4 != 2 & good == 1 & outin == 0), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 1 & intention4 != 2 & good == 0 & outin == 0), by(intention4) // bad outcome
				
				* bad v private
				ranksum vote_ if(intention4 != 0 & intention4 != 3 & good == 1 & outin == 0), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 0 & intention4 != 3 & good == 0 & outin == 0), by(intention4) // bad outcome
				
				* bad v certain
				ranksum vote_ if(intention4 != 1 & intention4 != 3 & good == 1 & outin == 0), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 1 & intention4 != 3 & good == 0 & outin == 0), by(intention4) // bad outcome
				
				* certain v private
				ranksum vote_ if(intention4 != 2 & intention4 != 3 & good == 1 & outin == 0), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 2 & intention4 != 3 & good == 0 & outin == 0), by(intention4) // bad outcome

			* Outgroup 
				* good v bad
				ranksum vote_ if(intention4 != 0 & intention4 != 1 & good == 1 & outin == 1), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 0 & intention4 != 1 & good == 0 & outin == 1), by(intention4) // bad outcome
				
				* good v private
				ranksum vote_ if(intention4 != 0 & intention4 != 2 & good == 1 & outin == 1), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 0 & intention4 != 2 & good == 0 & outin == 1), by(intention4) // bad outcome
				
				* good v certain
				ranksum vote_ if(intention4 != 1 & intention4 != 2 & good == 1 & outin == 1), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 1 & intention4 != 2 & good == 0 & outin == 1), by(intention4) // bad outcome
				
				* bad v private
				ranksum vote_ if(intention4 != 0 & intention4 != 3 & good == 1 & outin == 1), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 0 & intention4 != 3 & good == 0 & outin == 1), by(intention4) // bad outcome
				
				* bad v certain
				ranksum vote_ if(intention4 != 1 & intention4 != 3 & good == 1 & outin == 1), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 1 & intention4 != 3 & good == 0 & outin == 1), by(intention4) // bad outcome
				
				* certain v private
				ranksum vote_ if(intention4 != 2 & intention4 != 3 & good == 1 & outin == 1), by(intention4) // good outcome
				ranksum vote_ if(intention4 != 2 & intention4 != 3 & good == 0 & outin == 1), by(intention4) // bad outcome
		

*~* Appendix H: Experiment 4 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

use Experiment4Data, clear

* Clean Data
	gen aVoteIncumbent = (PolicyAVote == 1) if PolicyAVote != .
	label def inclab 0 "Challenger" 1 "Incumbent"
	label val aVoteIncumbent inclab
	label var aVoteIncumbent "Retain Incumbent if Good Outcome"

	gen bVoteIncumbent = (PolicyBVote == 1) if PolicyBVote != .
	label val bVoteIncumbent inclab
	label var bVoteIncumbent "Retain Incumbent if Bad Outcome"

	gen revealedIntention = intention
	replace revealedIntention = . if revealedIntention == -99
	label var revealedIntention "Saw Intended Outcome"

	gen aVoteGoodIntent = (VoteIntentionAA == 1) if VoteIntentionAA != .
	label val aVoteGoodIntent inclab
	label var aVoteGoodIntent "Retain Incumbent if Good Outcome + Good Intention" 

	gen aVoteBadIntent = (VoteIntentionBA == 1) if VoteIntentionBA != .
	label val aVoteBadIntent inclab
	label var aVoteBadIntent "Retain Incumbent if Good Outcome + Bad Intention"

	gen bVoteGoodIntent = (VoteIntentionAB == 1) if VoteIntentionAB != .
	label val bVoteGoodIntent inclab
	label var bVoteGoodIntent "Retain Incumbent if Bad Outcome + Good Intention"

	gen bVoteBadIntent = (VoteIntentionBB == 1) if VoteIntentionBB != .
	label val bVoteBadIntent inclab
	label var bVoteBadIntent "Retain Incumbent if Bad Outcome + Bad Intention"

	gen id = _n

	////The code below will create a stack of the intention conditions that did with the strategy method (i.e 1 participant has 2 observations for each policy [1 for good and 1 for bad])
	gen clone = 0
	tempfile temp1
	save "`temp1'"
	drop clone
	drop if intention != 1
	gen clone = 1
	append using "`temp1'"

	*This classification only works for the DVs created moving forward [the cloned person from the intentions condition is in both good and bad intentions)
	gen intention4 = .
	replace intention4 = 0 if intention == -99
	replace intention4 = 1 if intention == 0
	replace intention4 = 2 if intention == 1 & clone == 1
	replace intention4 = 3 if intention == 1 & clone == 0
	label def alb 0 "Certain" 1 "Private Intention" 2 "Bad Intention" 3 "Good Intention" 
	label val intention4 alb

	gen AIncumbent = aVoteIncumbent
	replace AIncumbent = aVoteBadIntent if intention == 1 & clone == 1
	replace AIncumbent = aVoteGoodIntent if intention == 1 & clone == 0 
	label val AIncumbent inclab
	label var AIncumbent "Retain Incumbent if Good Outcome"

	gen BIncumbent = bVoteIncumbent
	replace BIncumbent = bVoteBadIntent if intention == 1 & clone == 1
	replace BIncumbent = bVoteGoodIntent if intention == 1 & clone == 0 
	label val BIncumbent inclab
	label var BIncumbent "Retain Incumbent if Bad Outcome"
	
* Appendix A: Demographic Information

	* Table A1, Column 4
		mean age
		tab gender
		tab race
		tab party

* Appendix H: Experiment 4 results

	* Table H1

	*Unknown Payoff
		///Good outcome
		ttest AIncumbent if (intention4 == 3|intention4 == 1) & know == 0, by(intention4)
		ttest aVoteGood == aVoteBad if know == 0
		ttest AIncumbent if (intention4 == 2|intention4 == 1) & know == 0, by(intention4)
		///Bad outcome
		ttest BIncumbent if (intention4 == 3|intention4 == 1) & know == 0, by(intention4)
		ttest bVoteGood == bVoteBad if know == 0
		ttest BIncumbent if (intention4 == 2|intention4 == 1) & know == 0, by(intention4)
	*Indifferent Payoff
		///Good outcome
		ttest AIncumbent if (intention4 == 3|intention4 == 1) & know == 1, by(intention4)
		ttest aVoteGood == aVoteBad if know == 1
		ttest AIncumbent if (intention4 == 2|intention4 == 1) & know == 1, by(intention4)
		///Bad outcome
		ttest BIncumbent if (intention4 == 3|intention4 == 1) & know == 1, by(intention4)
		ttest bVoteGood == bVoteBad if know == 1
		ttest BIncumbent if (intention4 == 2|intention4 == 1) & know == 1, by(intention4)
	*Indifferent Sacrifice
		///Good outcome
		ttest AIncumbent if (intention4 == 3|intention4 == 1) & know == 2, by(intention4)
		ttest aVoteGood == aVoteBad if know == 2
		ttest AIncumbent if (intention4 == 2|intention4 == 1) & know == 2, by(intention4)
		///Bad outcome
		ttest BIncumbent if (intention4 == 3|intention4 == 1) & know == 2, by(intention4)
		ttest bVoteGood == bVoteBad if know == 2
		ttest BIncumbent if (intention4 == 2|intention4 == 1) & know == 2, by(intention4)

	* Figure H1		
		rename AIncumbent vote_1
		rename BIncumbent vote_2

		*This will uniquely identify rows, pre-reshape while id identifies observations
		gen id2 = _n

		reshape long vote_, i(id2) j(bad)

		rename bad good
		replace good = 0 if good == 2 & good != .
		label def go 0 "Bad Outcome" 1 "Good Outcome" 
		label val good go
		label var good "1 = Good Outcome, 0 Bad Outcome"
			
	cibar vote_, over(know intention4 good) ///
		barc(gs15 gs10 gs5) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 1)) ylabel(0(.1)1,grid)  ///
		ytitle("Proportion Voting For Incumbent", height(5)) ///
		xsize(8.5) ysize(4) ///
		legend(rows(1) pos(2) ring(0) region(lcolor(black) lpattern(solid))))
	graph export figH1.png, height(1500) replace
			

*~* Appendix I: Experiment 5 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

use Experiment5Data, clear

* Cleaning data

	gen aVoteIncumbent = (PolicyAVote == 1) if PolicyAVote != .
	label def inclab 0 "Challenger" 1 "Incumbent"
	label val aVoteIncumbent inclab
	label var aVoteIncumbent "Retain Incumbent if Good Outcome"

	gen bVoteIncumbent = (PolicyBVote == 1) if PolicyBVote != .
	label val bVoteIncumbent inclab
	label var bVoteIncumbent "Retain Incumbent if Bad Outcome"

	gen revealedIntention = intention
	replace revealedIntention = . if revealedIntention == -99
	label var revealedIntention "Saw Intended Outcome"

	gen aVoteGoodIntent = (VoteIntentionAA == 1) if VoteIntentionAA != .
	label val aVoteGoodIntent inclab
	label var aVoteGoodIntent "Retain Incumbent if Good Outcome + Good Intention" 

	gen aVoteBadIntent = (VoteIntentionBA == 1) if VoteIntentionBA != .
	label val aVoteBadIntent inclab
	label var aVoteBadIntent "Retain Incumbent if Good Outcome + Bad Intention"

	gen bVoteGoodIntent = (VoteIntentionAB == 1) if VoteIntentionAB != .
	label val bVoteGoodIntent inclab
	label var bVoteGoodIntent "Retain Incumbent if Bad Outcome + Good Intention"

	gen bVoteBadIntent = (VoteIntentionBB == 1) if VoteIntentionBB != .
	label val bVoteBadIntent inclab
	label var bVoteBadIntent "Retain Incumbent if Bad Outcome + Bad Intention"

	gen id = _n

	////The code below will create a stack of the intention conditions that did with the strategy method (i.e 1 participant has 2 observations for each policy [1 for good and 1 for bad])
	gen clone = 0
	tempfile temp1
	save "`temp1'"
	drop clone
	drop if intention != 1
	gen clone = 1
	append using "`temp1'"

	*This classification only works for the DVs created moving forward [the cloned person from the intentions condition is in both good and bad intentions)
	gen intention4 = .
	replace intention4 = 0 if intention == -99
	replace intention4 = 1 if intention == 0
	replace intention4 = 2 if intention == 1 & clone == 1
	replace intention4 = 3 if intention == 1 & clone == 0
	label def alb 0 "Certain" 1 "Private Intentions" 2 "Bad Intentions" 3 "Good Intentions" 
	label val intention4 alb

	gen AIncumbent = aVoteIncumbent
	replace AIncumbent = aVoteBadIntent if intention == 1 & clone == 1
	replace AIncumbent = aVoteGoodIntent if intention == 1 & clone == 0 
	label val AIncumbent inclab
	label var AIncumbent "Retain Incumbent if Good Outcome"

	gen BIncumbent = bVoteIncumbent
	replace BIncumbent = bVoteBadIntent if intention == 1 & clone == 1
	replace BIncumbent = bVoteGoodIntent if intention == 1 & clone == 0 
	label val BIncumbent inclab
	label var BIncumbent "Retain Incumbent if Bad Outcome"

	rename AIncumbent vote_1
	rename BIncumbent vote_2

	*This will uniquely identify rows, pre-reshape while id identifies observations
	gen id2 = _n

	reshape long vote_, i(id2) j(bad)

	replace bad = bad-1
	label def bo 0 "Good Outcome" 1 "Bad Outcome" 
	label val bad bo
	label var bad "1 = Bad Outcome, 0 Good Outcome"
	
	gen good = 0 if bad == 1
	replace good = 1 if bad == 0
	label def go 0 "Bad Outcome" 1 "Good Outcome" 
	label val good go
	label var good "1 = Good Outcome, 0 Bad Outcome"
	
* Appendix A: Demographic Characteristics 
	* Table A1, Column 5
	mean age
	tab gender
	tab race
	tab party

* Appendix I: Deciding for Others

	* Figure 3
	cibar vote_ if intention4 == 0, over(good) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.1).8,grid) xlabel( 1 "Bad Outcome" 2 "Good Outcome") yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel A" "Certain Condition") ///
		xsize(10) ysize(11) ///
		legend(off) saving(Fig1_PanelA, replace)) 
		
	cibar vote_ if intention4 == 1, over(good) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.1).8,grid) xlabel( 1 `" "Bad Outcome"   "(Likely Bad Intentions)" "' 2 `" "Good Outcome"   "(Likely Good Intentions)" "') yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel B" "Private Intentions") ///
		xsize(10) ysize(11) ///
		legend(off) saving(Fig1_PanelB, replace)) 
		
	cibar vote_ if intention4 > 1, over(intention4) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.1).8,grid) xlabel( 1 "Bad Intentions" 2 "Good Intentions") yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel C" "Known Intentions") ///
		xsize(10) ysize(11) ///
		legend(off) saving(Fig1_PanelC, replace)) 

	cibar vote_ if intention4 > 1, over(good intention4) ///
		barc(gs6 gs13) baropts(lcolor(gs0)) ///
		ciopts(lcolor(black)) graphopts(yscale(r(0 .8)) ylabel(0(.1).8,grid) yline(.5) ///
		ytitle("Proportion Voting For Incumbent", height(5)) title("Panel D" "Known Intentions") ///
		xsize(10) ysize(11) ///
		legend(rows(1) pos(12) ring(0) region(lcolor(black) lpattern(solid))) saving(Fig1_PanelD, replace)) 

	grc1leg2 Fig1_PanelA.gph Fig1_PanelB.gph Fig1_PanelC.gph Fig1_PanelD.gph, legendfrom(Fig1_PanelD.gph)
	graph export FigI1.png, heigh(1500) replace
	
	* Ttests
	ttest vote_ if intention4 == 0, by(good)
	ttest vote_ if intention4 == 1, by(good)

	
*~* Generating multi-study figures for appendix *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

	* Appendix E: Risk preferences and their effect on behavior
	
		* Figure E1:
		gr combine figE1_p1.gph figE1_p2.gph figE1_p3.gph, ycommon
		graph export figE1.png, height(1500) replace
		
		* Figure E2:
		grc1leg2 figE2_p1.gph figE2_p2.gph figE2_p3.gph  figE2_p4.gph, legendfrom(figE2_p1.gph) ycommon
		graph export figE2.png, height(1500) replace
		
		* Figure E3:
		grc1leg2 figE3_p1.gph figE3_p2.gph figE3_p3.gph figE3_p4.gph, legendfrom(figE3_p4.gph) ycommon xsize(5) ysize(6)
		graph export figE3.png, height(1500) replace

		
*~* Incumbent Decisions *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
	* Note: for each of the following commands, the policy best for the incumbent is
		* Policy A when incumbentPayoffA =  50
	
	* Table B1 - Incumbent decisions in Exp 1
	use Experiment1Incumbent, clear
	tab incumbentPayoffA noise, sum(chooseA) nost
	
	* Table B2 - Incumbent decisions in Exp 2
	use Experiment2Incumbent, clear
	tab incumbentPayoffA noise, sum(chooseA) nost
	
	* Table B3 - Incumbent decisions in Exp 3
	use Experiment3Incumbent, clear
	tab incumbentPayoffA noise, sum(chooseA) nost
	
	

